﻿using System.Collections.Generic;
using OhioState.Math.ThreeDimensional;
using Tao.OpenGl;

namespace OhioState.Graphics.OpenGL
{
    public class QuadList : IDrawable
    {
        public QuadList(int size)
        {
            vertices = new List<Vertex>(size);
        }
        public QuadList()
            : this(4*DefaultSize)
        {
        }
        public void AddVertex(Vertex vertex)
        {
            vertices.Add(vertex);
        }
        public void AddVertices(IList<Vertex> vertexList)
        {
            foreach (Vertex vertex in vertexList)
            {
                vertices.Add(vertex);
            }
        }

        internal void Clear()
        {
            vertices.Clear();
        }

        #region IDrawable Members
        public IBoundingVolume BoundingVolume
        {
            get { return null; }
        }

        public IMaterial Material
        {
            get { return material; }
            set { material = value; }
        }

        public void Render(IRenderPanel panel)
        {
            material.MakeActive(panel);
            Gl.glBegin(Gl.GL_QUADS);
            foreach (Vertex vertex in vertices)
            {
                Gl.glNormal3f(vertex.Normal.x, vertex.Normal.y, vertex.Normal.z);
                Gl.glVertex3f(vertex.Position.x, vertex.Position.y, vertex.Position.z);
            }
            Gl.glEnd();
            material.Deactivate(panel);
        }
        #endregion

        private IMaterial material;
        private IList<Vertex> vertices;
        private const int DefaultSize = 12;
    }
}
